﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Lamex.Library;
using Lamex.Library.CommonClass;

namespace Lamex.mMES.UI
{
    public partial class frmMES_Layout_Laminate : frmBaseChild
    {
        DataTable dtRGB = null;

        Bitmap imgFront;        //原始图片
        Bitmap imgBack;         //参考图片
        TextBox myText;         //显示信息
        string myInfo;

        public frmMES_Layout_Laminate()
        {
            InitializeComponent();
        }

        private void frmMES_Layout_Laminate_Load(object sender, EventArgs e)
        {
            dtRGB = Lamex.Base.BaseBuildSql.GetDataTableBySql(" select * From MES_Layout_Block_Color");
            
            string strPath = @"\\Tx-fs10\tx-fs1\LAMEX\MES\SysSource\Image\Layout";

            imgFront = new Bitmap(strPath + "\\Lamiante_Front.png");      
            imgBack = new Bitmap(strPath + "\\Laminate_Back.png");
            pictureBox1.Tag = "Front IMG";
            pictureBox1.Image = imgFront;       //加载图像                   
            pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;

            myText = new TextBox();
            this.Controls.Add(myText);
            myText.Multiline = true;
            myText.Enabled = false;
            myText.Parent = pictureBox1;
            myText.Width = 120;
            myText.Height = 64;
            myText.Visible = true;
        }

        private void frmMES_Layout_Laminate_MouseMove(object sender, MouseEventArgs e)
        {
            try
            {
                Color clr = imgBack.GetPixel(e.X + 10, e.Y + 10);         //获取在参考图对应坐标像素点的颜色信息
                myInfo = Lamex.Common.GetCheckRGBHelper.GetCheckRGB(clr, dtRGB);
                if (myInfo.Contains("无效区域"))
                {
                    pictureBox1.Cursor = Cursors.Arrow;
                    myText.Text = "";
                    myText.Visible = false;
                }
                else
                {
                    pictureBox1.Cursor = Cursors.Hand;          //设置手形
                    myText.Text = myInfo;
                    myText.Visible = true;
                    set_hand_shape(e.X, e.Y, myInfo);
                }
            }
            catch
            {
            }
        }

        private void set_hand_shape(int X, int Y, string msg)
        {
            //设置label位置
            if (X + 20 + myText.Width >= pictureBox1.Width)
                myText.Left = X - 20 - myText.Width;
            else
                myText.Left = X + 20;
            if (Y + 20 + myText.Height >= pictureBox1.Height)
                myText.Top = Y - 20 - myText.Height;
            else
                myText.Top = Y + 20;
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            Color clr = imgBack.GetPixel(MousePosition.X, MousePosition.Y - 100);         //获取在参考图对应坐标像素点的颜色信息
            myInfo = Lamex.Common.GetCheckRGBHelper.GetCheckRGB(clr, dtRGB);
            if (myInfo.Contains("生产-桌子"))
            {
                MdiTools.OpenChildForm(this.MdiParent as Lamex.Interface.IMdiForm, typeof(frmMES_Layout_Laminate), sender as ToolStripMenuItem);
            }
            else if (myInfo.Contains("生产-屏风"))
            {
                MdiTools.OpenChildForm(this.MdiParent as Lamex.Interface.IMdiForm, typeof(frmMES_Layout_Panel), sender as ToolStripMenuItem);
            }
            else if (myInfo.Contains("生产-椅子"))
            {
                MdiTools.OpenChildForm(this.MdiParent as Lamex.Interface.IMdiForm, typeof(frmMES_Layout_Seating), sender as ToolStripMenuItem);
            }
            else if (myInfo.Contains("生产-MCG"))
            {
                MdiTools.OpenChildForm(this.MdiParent as Lamex.Interface.IMdiForm, typeof(frmMES_Layout_MCG), sender as ToolStripMenuItem);
            }
            else
            {
                MessageBox.Show("单击位置为无效区域！");
            }
        }
    }
}